import React from 'react';

import {Button, Input} from 'antd';
import ObjectList from '../../components/ObjectList';

import router from '../../../utils/routerDecorator';
import {get, post} from '../../../logic/api';

const Operation = ObjectList.Operation;
const InputEx = ObjectList.InputEx;

export default class User extends React.Component {

  state = {

  }

  async onOk(r, f){
    if (f.pwd1 !== f.pwd2){
      return {
        ok:0,
        errmessage:"密码不一致"
      }
    }

    return {
      ok:1
    }
  }

  dataIndex = [{
    name:'pwd1',
    subtitle:'输入新密码'
  }, {
    name:'pwd2',
    subtitle:'确认新密码'
  }]

  async onOk(r, f){
    if (f.pwd1 !== f.pwd2){
      return {
        errmessage:"两次输入的密码不一致"
      }
    }
    if (!(/^.{8,24}$/.test(f.pwd1))){
      return {
        errmessage:"密码为8-24位"
      }
    }
    var ret = await post('/admin/user/changepwd', {
      mobile:r.mobile,
      secret:f.pwd1
    });

    console.log(ret);
    return ret;
  }

  render(){
    return <Operation 
      text = "修改密码" 
      record = {this.props.record}
      dataIndex = {this.dataIndex} 
      fetchData = {async ()=>{
        return {
          data:{
            pwd1:"",
            pwd2:""
          }
        }
      }}
      onOk = {async (r, f)=>{
        return await this.onOk(r, f);
    }}/>
  }
}